package com.sunny.ihealth.ui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;

import com.squareup.picasso.Picasso;
import com.sunny.ninepictureview.NinePictureAdapter;
import com.sunny.ninepictureview.PressGrayImageView;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.datatype.BmobFile;

/**
 * 帖子界面的九图适配器
 * Created by Sunny  An on 2016/5/24.
 */
public class PostNinePicAdapter extends NinePictureAdapter {

    private static final ColorDrawable gray = new ColorDrawable(Color.GRAY);
    private static final ColorDrawable darkGray = new ColorDrawable(Color.DKGRAY);

    private Context context;
    private List<String> picUrls;

    public PostNinePicAdapter(Context context, List<String> picUrls, int nothing) {
        this.context = context;
        this.picUrls = picUrls;
    }

    public PostNinePicAdapter(Context context, List<BmobFile> files) {
        this.context = context;

        if (files != null && files.size() != 0) {
            picUrls = new ArrayList<>();
            for (BmobFile file : files) {
                picUrls.add(file.getUrl());
            }
        }
    }

    @Override
    public int getCount() {
        return picUrls != null ? picUrls.size() : 0;
    }


    @Override
    public View getView(int position) {
        PressGrayImageView imageView = new PressGrayImageView(context);
        Picasso
                .with(context)
                .load(picUrls.get(position))
                .config(Bitmap.Config.RGB_565)
                .placeholder(gray)
                .error(darkGray)
                .into(imageView);
        return imageView;
    }
}
